package com.leonardo.persistenceme.model.persistancehandlers;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

public class ShortPersistenceHandler extends PersistenceHandler {

	public void persist(Object obj, DataOutputStream stream) throws IOException {
		if(obj == null) {
			stream.writeShort(Short.MIN_VALUE);
			return;
		}
		Short value = (Short) obj;
		stream.writeShort(value.shortValue());
	}

	public Object recover(DataInputStream stream) throws IOException {
		short value = stream.readShort();
		if(value == Short.MIN_VALUE)
			return null;
		return new Short(value);
	}

}
